const callbacks = [];
let pending = false;
function flushCallbacks () {
  pending = false
  const copies = callbacks.slice(0)
  callbacks.length = 0
  for (let i = 0; i < copies.length; i++) {
    copies[i]()
  }
}
let timerFunc;
if (typeof Promise !== 'undefined') {
  const p = Promise.resolve()
  timerFunc = () => {
    p.then(flushCallbacks)
  }
}
export function nextTick(cb) {
  callbacks.push(() => {
    if (cb) {
      try {
        cb()
      } catch (e) {
        // handleError(e, ctx, 'nextTick')
      }
    }
  })
  if (!pending) {
    pending = true
    timerFunc()
  }
}